﻿import java.io.File;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.xml.XmlConfiguration;

/**
 * Jetty6Runner.java 1.0 2007-4-22 下午10:35:25,创建 by yangfan
 */

/**
 *
 * @author yangfan
 * @version 1.0 2007-4-22 下午10:35:25,创建
 */
public class Jetty6Runner
{
	public static void main(String[] args)
	{
		try
		{
			long stime = System.currentTimeMillis();
			new Jetty6Runner().runJetty();
			System.err.println("-----------start jetty in [" + (System.currentTimeMillis() - stime) + "ms]");
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
			throw new RuntimeException("无法启动jetty");
		}
	}

	public void runJetty() throws Exception
	{
		Server server = new Server();
		Connector connector = new SelectChannelConnector();
		connector.setPort(8080);
		server.setConnectors(new Connector[] {connector});

//		ContextHandler handler = new ContextHandler();
//		handler.setContextPath("/in4jbbs");
//		handler.setResourceBase("./webapp");
//		handler.setClassLoader(getClass().getClassLoader());
//		server.setHandler(handler);

		WebAppContext ctx = new WebAppContext("./webapp","/in4jbbs");
		server.setHandler(ctx);
		server.start();
	}

	public void runJettyUseXmlConfig() throws Exception
	{
		Server server = new Server();
		XmlConfiguration configuration = new XmlConfiguration(new File("jetty6.xml").toURL());
		configuration.configure(server);
		server.start();
	}
}
